home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / HardwareProjects / MC68010.lha / MC68010 / CHOP.c < prev    next >
Encoding:
Text File  |  1986-04-08  |  1.5 KB  |  78 lines

  1. /*******************************************
  2.  *  Chop                                   *
  3.  *                                         *
  4.  *  by J S Plegge                          *
  5.  *                                         *
  6.  *  Truncate files to specified length     *
  7.  *                                         *
  8.  *  USAGE:  Chop <input> <output> <size>   *
  9.  *                                         *
  10.  *******************************************/
  11.  
  12. #include <stdio.h>
  13. #include <ctype.h>
  14.  
  15. usage()
  16.  
  17. {
  18.  
  19. puts("Usage:  CHOP <input> <output> <size>");
  20. }
  21.  
  22. main(argc, argv)
  23.  
  24. int argc;
  25. char *argv[];
  26.  
  27. {
  28. int i;
  29. int c;
  30. FILE *in, *out;
  31. long int l;
  32.  
  33. if (argc < 4)
  34.    {
  35.    puts("Bad arguments.");
  36.    usage();
  37.    exit(20);
  38.    }
  39.  
  40. l=atol(argv[3]);
  41.  
  42.  
  43.  
  44. if (l <= 0)
  45.  
  46.    {
  47.  
  48.    puts("Invalid size.");
  49.    usage();
  50.    exit(20);
  51.    }
  52.  
  53. if ((in = fopen (argv[1], "r")) == 0)
  54.    {
  55.    printf("Can't open %s\n", argv[1]);
  56.    exit(20);
  57.    }
  58.  
  59. if ((out = fopen (argv[2], "w")) == 0)
  60.    {
  61.    printf("Can't open %s\n", argv[2]);
  62.    exit(20);
  63.    }
  64.  
  65. printf("Writing %d bytes from %s to %s \n",l,argv[1],argv[2]);
  66.  
  67. i=0;
  68.  
  69. while (((c = getc(in)) !=EOF) && (i < l))
  70.   {
  71.   i=i+1;
  72.   putc(c, out);
  73.   }                     /*  endwhile  */
  74.  
  75. if (i == l)
  76.    puts("Done!");
  77. else
  78.    puts("CHOP ended at EOF on input.");
  79.  
  80. fclose (in);
  81. fclose (out);
  82.  
  83. }                    /* end of program  */
  84.